const wrapAsync = (fn) => {
    return (req, res, next) => {
        fn(req, res, next).catch(err => {
            const statusCode = err.statusCode || 500
            res.status(statusCode).json({
                code: statusCode,
                message: err.message || '服务器内部错误'
            })
            if (req.db && req.db.rollback) {
                req.db.rollback().catch(rollbackErr => {
                    console.error('事务回滚失败:', rollbackErr)
                })
            }
        })
    }
}
module.exports = wrapAsync